package logic

import (
	"context"
	"goodsrpc/mysql"

	"goodsrpc/goods"
	"goodsrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MyReleaseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMyReleaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MyReleaseLogic {
	return &MyReleaseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *MyReleaseLogic) MyRelease(in *goods.MyReleaseRequest) (*goods.MyReleaseResponse, error) {
	// todo: add your logic here and delete this line
	var h mysql.House
	release, err := h.MyRelease(in.UserId)
	if err != nil {
		return nil, err
	}
	var HouseList []*goods.MyReleaseList
	for _, i := range release {
		list := goods.MyReleaseList{
			Name:        i.Name,
			Price:       uint64(i.Price),
			FacePrice:   uint64(i.FacePrice),
			HouseNumber: i.HouseNumber,
			ListingTime: i.ListingTime,
			State:       i.State,
			UserId:      i.UserId,
		}
		HouseList = append(HouseList, &list)
	}

	return &goods.MyReleaseResponse{
		List: HouseList,
	}, nil
}
